package com.taobao.databindingdemo;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;

import com.taobao.databindingdemo.databinding.AppDatabindMainBinding;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);

        super.onCreate(savedInstanceState);

        setContentView(R.layout.app_databind_main);

        TextView textView = (TextView) findViewById(R.id.xxxxx_aar);

        AppDatabindMainBinding binding = DataBindingUtil.setContentView(this, R.layout.app_databind_main);
        final User user = new User("Test", "User");
        binding.setUser(user);

        EditText editText = (EditText) findViewById(R.id.inputText_aar);
        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                System.out.println(s);
                user.setFirstName(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

    }
}
